﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using DiscountSharing.LocalModels;

namespace DiscountSharing.LocalControls
{
    public partial class CategoryPicker : UserControl
    {
        private bool isOpen = false;
        private ObservableCollection<String> types;
        public string SelectedCategory { get; set; }

        public CategoryPicker()
        {
            InitializeComponent();
            types = new ObservableCollection<string>();
            types.Add("Clothes");

            Loaded += (o, e) =>
                {
                    CategoryList.DataContext = types;
                };

            CategoryList.SelectionChanged += (o, e) =>
                {
                    if (e.AddedItems.Count != 0 && isOpen)
                    {
                        SelectedCategory = e.AddedItems[0].ToString();
                        object obj = SelectedCategory;
                        types.Clear();
                        types.Add((String)obj);
                        CategoryList.DataContext = types;
                        isOpen = false;
                    }
                    else if (e.AddedItems.Count != 0 && !isOpen)
                    {
                        types.Clear();
                        types.Add("Food");
                        types.Add("Clothes");
                        types.Add("Services");
                        types.Add("Entertainment");
                        types.Add("Electronics");
                        CategoryList.DataContext = types;
                        isOpen = true;
                    }
                };
        }
    }
}
